import { getBussiDictsFromCache } from '@/api/api'

export const DictMixin = {
  data() {
    return {
      countryDictList:[],
      userList:[],
      disCodeList:[],
      buildRuleList:[],
    }
  },
  methods: {
    async  getCountryList(model, fieldName) {
      const res = await getBussiDictsFromCache('countryCode')
      if (res.success) {
        this.countryDictList = res.result
      }
      const matchCountry = this.countryDictList.filter(item => (item.threeletters === model[fieldName] || item.twoletters === model[fieldName] || item.digital === model[fieldName]))
      if (matchCountry != null && matchCountry.length > 0) {
        model[fieldName] = matchCountry[0].threeletters
      }
    },
    async  getAllUserList() {
      const res = await getBussiDictsFromCache('USER_LIST')
      if (res.success) {
        this.userList = res.result
      }
    },
    async  getAllDisCodeList() {
      const res = await getBussiDictsFromCache('allAgency')
      if (res.success) {
        this.disCodeList = res.result
      }
    },
    async  getBuildRuleList() {
      const res = await getBussiDictsFromCache('supsBuildRuleDict')
      if (res.success) {
        this.buildRuleList = res.result
      }
    },
    async  getFundRiskLeveList() {
      const res = await getBussiDictsFromCache('FUND_RISK_LEVEL')
      if (res.success) {
        this.fundRiskLeveList = res.result
      }
    },
    async  getChannelRiskLeveList() {
      const res = await getBussiDictsFromCache('CHANNEL_RISK_LEVEL')
      if (res.success) {
        this.channelRiskLeveList = res.result
      }
    },
  },
}